package com.hmall.user.web;

import com.hmall.user.mapper.UserMapper;
import com.hmall.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;
    @Autowired
    private UserMapper userMapper;

    /**
     * 下单扣款
     * @param userId
     * @param money
     */
    @PutMapping("/money/{userId}/{money}")
    public void deductMoney(@PathVariable("userId") Long userId,@PathVariable("money") Long money){
        log.info("下单扣款：{},{}",userId,money);
        userService.deductMoney(userId,money);
    }

    /**
     * 金额回滚
     * @param id
     * @param money
     */
    @PutMapping("/refund/{id}/{money}")
    public void refund(@PathVariable("id") String id,@PathVariable("money") String money){
        log.info("金额回滚：{},{}",id,money);
        userMapper.refund(id,money);
    }
}
